<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑集合信息</title>
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="__STATIC__/bootstrap-table/js/dropdown.js"></script>
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">

    <link type="text/css" rel="stylesheet" href="__STATIC__/uploads/css/fileinput.css"/>
    <script type="text/javascript" src="__STATIC__/uploads/js/fileinput.js"></script>
    <script type="text/javascript" src="__STATIC__/uploads/js/fileinput_locale_zh.js"></script>
    <link type="text/css" rel="stylesheet" href="__STATIC__/uploads/css/bootstrap.min.css"/>
</head>
<body>
<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>
<form class="layui-form" onsubmit="return false" action="" id="up" style="width: 40%">
    <input id="id" value="{$result.id}" hidden>
    <div class="layui-form-item">
        <label class="layui-form-label">集合标题</label>
        <div class="layui-input-block">
            <input type="text" id="title" name="title" value="{$result.title}" required  lay-verify="required" placeholder="{$result.title}" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">集合图片</label>
        <div class="layui-input-block">
            <img src="{$result.icon_path}" style="width: 200px;height: 200px">
            <input type="file" name="file" id="uploads" multiple class="file-loading" style="width: 20%;height:20%;"/>
            <input type="text"  id="icon_path" value="{$result.icon_path}" hidden>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">集合视频</label>
        <div class="layui-input-block">
            <video src="{$result.video_path}" controls="controls" style="width:200px;height: 150px"></video>
            <input type="file" name="file" id="video" multiple class="file-loading" />
            <input type="text" id="video_path" value="{$result.video_path}" hidden>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">章节介绍</label>
        <div class="layui-input-block">
            <textarea lay-verify="article_desc" id="introduce"  name="text" style="width: 100%;height: 100px">{$result.introduce}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选择教师</label>
        <div class="layui-input-block">
            <select id="jsname" lay-verify="required">
                <option value="{$result.jsname}">{$result.get_table_teacher.title}</option>
                {foreach $teacher as $val}
                    <option value="{$val.id}">{$val.title}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选择地区</label>
        <div class="layui-input-block">
            <select id="city" lay-verify="required" >
                <option value="{$result.city}">{$result.get_region.region_name}</option>
                {foreach $city as $val}
                <option value="{$val.id}">{$val.region_name}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="sub">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
</html>
<script>
    $("#uploads").fileinput({
        language: 'zh', //设置语言
        uploadUrl: "{:url('/common/img')}", //上传的地址
        uploadExtraData: {path:'/public/uploads/bar/img'},
        allowedFileExtensions: ['jpg', 'gif', 'png'],//接收的文件后缀
        showUpload: true, //是否显示上传按钮
        showCaption: false,//是否显示标题
        browseClass: "btn btn-primary", //按钮样式
        //dropZoneEnabled: false,//是否显示拖拽区域
        minImageWidth: 200, //图片的最小宽度
        minImageHeight: 200,//图片的最小高度
        maxImageWidth: 200,//图片的最大宽度
        maxImageHeight: 200,//图片的最大高度
//        maxFileSize: 0,//单位为kb，如果为0表示不限制文件大小
//        minFileCount: 0,
        maxFileCount: 1, //表示允许同时上传的最大文件个数
        enctype: 'multipart/form-data',
        validateInitialCount:true,
        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！"
    }).on("fileuploaded", function (event, data, previewId, index) {
        $("#icon_path").val(data.response.img)
    });
</script>
<script>
    layui.use('layedit', function(){
        layedit = layui.layedit;
        index = layedit.build('introduce', {tool: [
            'strong' //加粗
            ,'italic' //斜体
            ,'underline' //下划线
            ,'del' //删除线
        ]}); //建立编辑器
        //layedit.sync(index);
        edit = layedit.getContent(index);
    });
</script>
<script>
    $("#video").fileinput({
        language: 'zh', //设置语言
        uploadUrl: "{:url('/common/video')}", //上传的地址
        uploadExtraData: {path:'/public/uploads/bar/video'},
        previewFileType:"video",
        allowedFileExtensions: ['mp4'],//接收的文件后缀
        showUpload: true, //是否显示上传按钮
        showCaption: false,//是否显示标题
        browseClass: "btn btn-primary", //按钮样式
        //dropZoneEnabled: false,//是否显示拖拽区域
        minImageWidth: 200, //图片的最小宽度
        minImageHeight: 200,//图片的最小高度
        maxImageWidth: 200,//图片的最大宽度
        maxImageHeight: 200,//图片的最大高度
        maxFileSize: 0,//单位为kb，如果为0表示不限制文件大小
        //minFileCount: 0,
        maxFileCount: 1, //表示允许同时上传的最大文件个数
        enctype: 'multipart/form-data',
        validateInitialCount:true,
        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！"

    }).on("filepreupload", function (event, data, previewId, index) {
        layer.load(2, {time: 100*1000});
    }).on("fileuploaded", function(event, data, previewId, index) {
        layer.closeAll();
        $("#video_path").val(data.response.video)
    });
</script>
<script>
    //修改章节信息
    $("#sub").click(function(){
        var id = $("#id").val();
        var title = $("#title").val();
        var introduce = layedit.getContent(index)
        var icon_path = $("#icon_path").val();
        var video_path = $("#video_path").val();
        var city = $("#city").val();
        var jsname = $("#jsname").val();
        if(!title || !introduce ){
            layer.msg('请不要输入空白的信息',{icon:5,time:2000});
            return;
        }
        $.ajax({
            url:"{:url('/video/updateGather')}",
            type:"post",
            data:{id:id,title:title,introduce:introduce,icon_path:icon_path,video_path:video_path,city:city,jsname:jsname},
            dataType:"json",
            beforeSend:function () {
                index = layer.load(2, {time: 100*1000});
            },
            success:function(res){
                if(res.code){
                    layer.close(index);
                    layer.msg(res.msg,{icon:1,time:2000},function(){
                        window.location.reload();
                    });
                    return;
                }else{
                    layer.msg(res.msg,{icon:5,time:2000});
                    return;
                }
            }
        })
    })


</script>